package yx.action;

import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.springframework.beans.factory.annotation.Autowired;

import yx.service.CorporationServiceInt;
import yx.vo.CorporationVO;
import yx.vo.JsonVO;

import com.opensymphony.xwork2.ModelDriven;

@ParentPackage("basePackage")
@Namespace("/")
@Action(value = "corporationAction")
public class CorporationAction extends BaseAction implements ModelDriven<CorporationVO> {
	/**
	 * Logger for this class
	 */
	private static final Logger logger = Logger.getLogger(CorporationAction.class);

	private CorporationVO corporation = new CorporationVO();

	@Override
	public CorporationVO getModel() {
		return corporation;
	}

	private CorporationServiceInt corporationService;

	public CorporationServiceInt getCorporationService() {
		return corporationService;
	}

	@Autowired
	public void setCorporationService(CorporationServiceInt corporationService) {
		this.corporationService = corporationService;
	}

	public void queryCorporation() {
		super.writeJson(corporationService.datagrid(corporation));
	}

	public void addCorporation() {
		JsonVO j = new JsonVO();
		try {
			CorporationVO u = corporationService.save(corporation);
			j.setSuccess(true);
			j.setMsg("增加成功！");
			j.setObj(u);
		} catch (Exception e) {
			j.setMsg(e.getMessage());
		}
		super.writeJson(j);
	}

	public void removeCorporation() {
		corporationService.remove(corporation.getIds());
		JsonVO j = new JsonVO();
		j.setSuccess(true);
		j.setMsg("删除成功！");
		super.writeJson(j);
	}

	public void editCorporation() {
		CorporationVO u = corporationService.edit(corporation);
		JsonVO j = new JsonVO();
		j.setSuccess(true);
		j.setMsg("编辑成功！");
		j.setObj(u);
		super.writeJson(j);
	}

}
